{extend name="base"/}
{block name="resources"}
<link rel="stylesheet" type="text/css" href="__STATIC__/ext/layui/extend/cascader/cascader.css"/>
<style>
	.layui-layer-content .form-wrap {padding: 0}
	.layui-layer-page .layui-layer-content {overflow-y: auto!important;}
	.layui-layout-admin .layui-body .body-content {background: none;padding: 0}
	.info-wrap {display: flex}
	.info-wrap .layui-card {flex: 1;margin-top: 0}
	.info-wrap .layui-card:first-child {margin-right: 15px}
	.member-info {display: flex}
	.member-info .headimg {margin-right: 15px;width: 70px;height: 70px;display: flex;align-items: center;justify-content: center;overflow: hidden}
	.member-info .headimg img {max-width: 100%;height: auto}
	.member-info .info {flex: 1;width: 0;display: flex;flex-wrap: wrap}
	.member-info .info .data-item {width: 50%;padding-right: 10px;box-sizing: border-box;line-height: 30px}
	.member-info .data-item .layui-icon {cursor: pointer}
	.layui-tab-content {padding: 0}
	.screen {margin: 15px 0}
	.select-level-layer .layui-layer-content {overflow: unset!important;}
</style>
{/block}

{block name="main"}
<div class="info-wrap">
	<div class="layui-card card-common card-brief">
		<div class="layui-card-header">
			<div>
				<span class="card-title">基本信息</span>
			</div>
		</div>
		<div class="layui-card-body">
			<div class="member-info">
				<div class="headimg">
					{notempty name="$member_info.data.headimg"}
					<img src="{:img($member_info.data.headimg)}" alt="">
					{else/}
					<img src="{:img('public/static/img/default_img/head.png')}" alt="">
					{/notempty}
				</div>
				<div class="info">
					<div class="data-item">
						<span>用户名：</span>
						<span>{$member_info.data.username}</span>
					</div>
					<div class="data-item">
						<span>昵称：</span>
						<span>{$member_info.data.nickname}</span>
						<i class="layui-icon text-color" style="margin-left: 5px;" onclick="editNickname(this)"> </i>
					</div>
					<div class="data-item">
						<span>手机号：</span>
						<span>{notempty name="$member_info.data.mobile"}{$member_info.data.mobile}{else/}暂无{/notempty}</span>
						<i class="layui-icon text-color" style="margin-left: 5px;" onclick="editMobile(this)"> </i>
					</div>
					{if $member_info.data.is_member}
					<div class="data-item">
						<span>会员码：</span>
						<span>{notempty name="$member_info.data.member_code"}{$member_info.data.member_code}{else/}--{/notempty}</span>
					</div>
					{/if}
					<div class="data-item">
						<span>真实姓名：</span>
						<span>{notempty name="$member_info.data.realname"}{$member_info.data.realname}{else/}暂无{/notempty}</span>
						<i class="layui-icon text-color" style="margin-left: 5px;" onclick="editRealname(this)"> </i>
					</div>
					<div class="data-item">
						<span>性别：</span>
						<span>
							{switch name="$member_info.data.sex"}
							{case value="0"}未知{/case}
							{case value="1"}男{/case}
							{case value="2"}女{/case}
							{/switch}
						</span>
						<i class="layui-icon text-color" style="margin-left: 5px;" onclick="editSex(this)"> </i>
					</div>
					<div class="data-item">
						<span data-value="{$member_info.data.birthday}">生日：</span>
						<span>{notempty name="$member_info.data.birthday"}{:date('Y-m-d', $member_info.data.birthday)}{else/}未知{/notempty}</span>
						<i class="layui-icon text-color" style="margin-left: 5px;" onclick="editBirthday(this)"> </i>
					</div>
					<div class="data-item">
						<span>会员等级：</span>
						<span>{$member_info.data.member_level_name}</span>
						<i class="layui-icon text-color" style="margin-left: 5px;" onclick="editMemberLevel(this)"> </i>
					</div>
					<div class="data-item">
						<span>注册时间：</span>
						<span>{:time_to_date($member_info.data.reg_time)}</span>
					</div>
					<div class="data-item">
						<span>来源渠道：</span>
						<span>{$member_info.data.login_type_name}</span>
					</div>
					<div class="data-item">
						<span>最后访问时间：</span>
						<span>{:time_to_date($member_info.data.last_visit_time)}</span>
					</div>
					<div class="data-item" style="width: 100%">
						<span>会员地址：</span>
						<span>{$member_info.data.full_address ? $member_info.data.full_address : '--'} {$member_info.data.address ? $member_info.data.address : ''}</span>
						<i class="layui-icon text-color" style="margin-left: 5px;" onclick="editMemberAddress(this)"> </i>
					</div>

					<input type="hidden" name="member_id" value="{$member_info.data.member_id}" />
					<input type="hidden" class="birthday" value="{$member_info.data.birthday}" />
				</div>
			</div>
		</div>
	</div>

	<div class="layui-card card-common card-brief">
		<div class="layui-card-header">
			<div>
				<span class="card-title">账户信息</span>
			</div>
		</div>
		<div class="layui-card-body">
			<div class="member-info">
				<div class="info">
					<div class="data-item">
						<span>储值余额：</span>
						<span id="member_balance">{:moneyFormat($member_info.data.balance)}</span>
						<i class="layui-icon text-color" style="margin-left: 5px;" data-num="{$member_info.data.balance}" onclick="saveBalance(this)"> </i>
					</div>
					<div class="data-item">
						<span>现金余额：</span>
						<span>{:moneyFormat($member_info.data.balance_money)}</span>
					</div>
					<div class="data-item">
						<span>积分：</span>
						<span id="member_point">{:round($member_info.data.point)}</span>
						<i class="layui-icon text-color" style="margin-left: 5px;" data-num="{$member_info.data.point}" onclick="savePoint(this)"> </i>
					</div>
					<div class="data-item">
						<span>成长值：</span>
						<span id="member_growth">{$member_info.data.growth}</span>
						<i class="layui-icon text-color" style="margin-left: 5px;" data-num="{$member_info.data.growth}" onclick="saveGrowth(this)"> </i>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<div class="layui-card card-common card-brief">
	<div class="layui-card-header">
		<div>
			<span class="card-title">账户明细</span>
		</div>
	</div>
	<div class="layui-card-body layui-tab layui-tab-brief" lay-filter="edit_user_tab">
		<ul class="layui-tab-title">
			<li class="layui-this" lay-id="basic_info">余额</li>
			<li lay-id="basic_info">积分</li>
			<li lay-id="basic_info">成长值</li>
			<li lay-id="basic_info">订单管理</li>
			<li lay-id="basic_info">收货地址</li>
			<li lay-id="basic_info">收藏记录</li>
			<li lay-id="basic_info">浏览记录</li>
			<li lay-id="basic_info">优惠券</li>
			{if addon_is_exit('cardservice') == 1 }
			<li lay-id="basic_info">卡项</li>
			{/if}
		</ul>
		<div class="layui-tab-content">

			<div class="layui-tab-item layui-show">
				<iframe src="{:url('shop/member/accountdetail',array('member_id'=>$member_info.data.member_id, 'account_type' => 'balance,balance_money'))}" style="width:100%;height:100vh;border:0"></iframe>
			</div>
			<div class="layui-tab-item">
				<iframe src="{:url('shop/member/accountdetail',array('member_id'=>$member_info.data.member_id, 'account_type' => 'point'))}" style="width:100%;height:100vh;border:0"></iframe>
			</div>
			<div class="layui-tab-item">
				<iframe src="{:url('shop/member/accountdetail',array('member_id'=>$member_info.data.member_id,'account_type' => 'growth'))}" style="width:100%;height:100vh;border:0"></iframe>
			</div>

			<div class="layui-tab-item">
				<iframe src="{:url('shop/member/order',array('member_id'=>$member_info.data.member_id))}" style="width:100%;height:100vh;border:0"></iframe>
			</div>
			<div class="layui-tab-item">
				<iframe src="{:url('shop/member/addressdetail',array('member_id'=>$member_info.data.member_id))}" style="width:100%;height:100vh;border:0"></iframe>
			</div>
			<div class="layui-tab-item">
				<iframe src="{:url('shop/goods/membergoodscollect',array('member_id'=>$member_info.data.member_id))}" style="width:100%;height:100vh;border:0"></iframe>
			</div>
			<div class="layui-tab-item">
				<iframe src="{:url('shop/goods/membergoodsbrowse',array('member_id'=>$member_info.data.member_id))}" style="width:100%;height:100vh;border:0"></iframe>
			</div>
			<div class="layui-tab-item">
				<iframe src="{:url('shop/member/membercoupon',array('member_id'=>$member_info.data.member_id))}" style="width:100%;height:100vh;border:0"></iframe>
			</div>
			{if addon_is_exit('cardservice') == 1 }
			<div class="layui-tab-item">
				<iframe src="{:addon_url('cardservice://shop/card/membergoodscard',array('member_id'=>$member_info.data.member_id))}" style="width:100%;height:100vh;border:0"></iframe>
			</div>
			{/if}
		</div>
	</div>
</div>
{/block}

{block name="script"}
<script>
	var birthday = $(".birthday").val();
	$("input[name=birthday]").attr("value", ns.time_to_date(birthday, "YYYY-MM-DD"));

	layui.extend({
		layCascader: '__STATIC__/ext/layui/extend/cascader/cascader'
	})

	var layCascader, areaTree = [];
	layui.use(['form', 'layCascader'], function() {
		var form = layui.form,
				repeat_flag = false; //防重复标识
		layCascader = layui.layCascader;
		form.render();

		/**
		 * 表单验证
		 */
		form.verify({
			mobile: function(value) {
				var reg = /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[89])\d{8}$/;
				if (value == '') {
					return;
				}
				if (!reg.test(value)) {
					return '请输入正确的手机号码!';
				}
			},
			isemail: function(value) {
				var reg = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
				if (value == '') {
					return;
				}
				if (!reg.test(value)) {
					return '请输入正确的邮箱!';
				}
			}
		});

		var upload = new Upload({
			elem: '#headImg'
		});

		/**
		 * 监听提交
		 */
		form.on('submit(save)', function(data) {

			data.field.member_level_name = $(".member_level").find("option[value=" + data.field.member_level + "]").text();

			if (data.field.status == undefined) {
				data.field.status = 0;
			}

			// 删除图片
			if(!data.field.headimg) upload.delete();

			if(repeat_flag) return false;
			repeat_flag = true;

			$.ajax({
				url: ns.url("shop/member/editMember"),
				data: data.field,
				dataType: 'JSON', //服务器返回json格式数据
				type: 'POST', //HTTP请求类型
				success: function(res) {
					repeat_flag = false;
					if (res.code == 0) {
						layer.confirm('编辑成功', {
							title:'操作提示',
							btn: ['返回列表', '继续操作'],
							yes: function(){
								location.href = ns.url("shop/member/memberList")
							},
							btn2: function() {
								location.reload();
							}
						});
					}else{
						layer.msg(res.message);
					}
				}
			});
		});

	});

	function back() {
		location.href = ns.url("shop/member/memberList");
	}
</script>
<script>
	var date = {$member_info.data.reg_time};
	$(".reg-time").text(ns.time_to_date(date, "YYYY-MM-DD"));
	$("#member_point").text(parseInt("{$member_info.data.point}"));

	var form,
			table,
			laydate,
			laytpl;
	repeat_flag = false, //防重复标识
			currentDate = new Date(),
			minDate = "",
			reg = {
				required: /[\S]+/,
				mobile: /^1([38][0-9]|4[579]|5[0-3,5-9]|6[6]|7[0135678]|9[0-9])\d{8}$/
			};

	currentDate.setDate(currentDate.getDate() - 7);

	layui.use(['form', 'laydate', 'laytpl'], function() {
		form = layui.form;
		laydate = layui.laydate;
		laytpl = layui.laytpl;
		form.render();

		//开始时间
		laydate.render({
			elem: '#start_date',
			type: 'datetime'
		});

		//结束时间
		laydate.render({
			elem: '#end_date',
			type: 'datetime'
		});

		//根据账户类型获取来源类型
		form.on('select(account_type)', function (data) {

			$.ajax({
				type: "POST",
				url: ns.url("shop/member/getfromtype"),
				data: {type:data.value},
				dataType: 'JSON',
				success: function(res) {

					var html = '<option value="">请选择</option>';
					$.each(res,function(k,v){
						html += '<option value="'+k+'">'+v.type_name+'</option>';
					});

					$('.from_type').html(html);
					form.render();
				}
			});
		});

		/**
		 * 重新渲染结束时间
		 * */
		function reRender() {
			$("#reg_end_date").remove();
			$(".end-time").html('<input type="text" class="layui-input" name="reg_end_date" id="reg_end_date" placeholder="请输入结束时间">');
			laydate.render({
				elem: '#reg_end_date',
				min: minDate
			});
		}


		/**
		 * 表单验证
		 */
		form.verify({
			num: function(value) {
				var arrMen = value.split(".");
				var val = 0;
				if (arrMen.length == 2) {
					val = arrMen[1];
				}

				if (value == "") {
					return false;
				}
				if (val.length > 2) {
					return '保留小数点后两位'
				}
			}
		});

		/**
		 * 监听提交
		 */
		form.on('submit(search)', function(data) {
			table.reload({
				page: {
					curr: 1
				},
				where: data.field
			});
			return false;
		});

		form.on('submit(savePoint)', function(data) {
			if (repeat_flag) return false;
			repeat_flag = true;
			var point = {$member_info.data.point};
			if (data.field.adjust_num == 0) {
				layer.msg('调整数值不能为0');
				repeat_flag = false;
				return ;
			}
			if (point*1 + data.field.adjust_num*1 < 0) {
				layer.msg('积分不可以为负数');
				repeat_flag = false;
				return ;
			}
			$.ajax({
				type: "POST",
				url: ns.url("shop/member/adjustPoint"),
				data: data.field,
				dataType: 'JSON',
				success: function(res) {
					layer.msg(res.message);
					if (res.code == 0) {
						$("#member_point").html(res.data.point);
						$("#member_point").next().attr('data-num', res.data.point);
						layer.closeAll('page');
						table.reload();
					} else {
						repeat_flag = false;
					}
				}
			});
		});

		form.on('submit(saveBalance)', function(data) {
			if (repeat_flag) return false;
			repeat_flag = true;
			var balance = {$member_info.data.balance};
			if (data.field.adjust_num == 0) {
				layer.msg('调整数值不能为0');
				repeat_flag = false;
				return ;
			}

			if (balance*1 + data.field.adjust_num*1 < 0) {
				layer.msg('当前储值余额不可以为负数');
				repeat_flag = false;
				return ;
			}
			$.ajax({
				type: "POST",
				url: ns.url("shop/member/adjustBalance"),
				data: data.field,
				dataType: 'JSON',
				success: function(res) {
					layer.msg(res.message);
					if (res.code == 0) {
						// $("#member_balance").html(res.data.balance);
						// $("#member_balance").next().attr('data-num', res.data.balance);
						// layer.closeAll('page');
						// table.reload();
						location.reload();

					} else {
						repeat_flag = false;
					}
				}
			});
		});

		form.on('submit(saveGrowth)', function(data) {
			if (repeat_flag) return false;
			repeat_flag = true;
			var growth = {$member_info.data.growth};
			if (data.field.adjust_num == 0) {
				layer.msg('调整数值不能为0');
				repeat_flag = false;
				return ;
			}
			if (growth*1 + data.field.adjust_num*1 < 0) {
				layer.msg('成长值不可以为负数');
				repeat_flag = false;
				return;
			}
			$.ajax({
				type: "POST",
				url: ns.url("shop/member/adjustGrowth"),
				data: data.field,
				dataType: 'JSON',
				success: function(res) {
					layer.msg(res.message);

					if (res.code == 0) {
						$("#member_growth").html(res.data.growth);
						$("#member_growth").next().attr('data-num', res.data.growth);
						layer.closeAll('page');
						table.reload();
					} else {
						repeat_flag = false;
					}
				}
			});
		});

		form.on('checkbox(memberlevel)', function(data){
			$('#setMemberLevel input[type="checkbox"]').prop('checked', false);
			$(data.elem).prop('checked', true);
			form.render();
		})
	});

	function savePoint(e) {
		var point = $(e).attr('data-num');
		var data = {
			point : point
		};
		laytpl($("#point").html()).render(data, function(html) {
			layer.open({
				title: '调整积分',
				skin: 'layer-tips-class',
				type: 1,
				area: ['800px'],
				content: html,
				end: function () {
					repeat_flag = false;
				}
			});
		});


		$(".integral-bounced .amount input").on("input propertychange",function(val){
			var newIntegral = parseInt($(this).val());
			if (!isNaN(newIntegral)) $(this).val(newIntegral);
			var currIntegral = parseInt($(".integral-bounced .account-value").text());

			if (newIntegral + currIntegral < 0){
				layer.msg("调整数额与当前值积分数相加不能小于0");
				$(this).val(-currIntegral);
				return false;
			}

		})
	}

	function saveBalance(e) {
		var balance = $(e).attr('data-num');
		var data = {
			balance : balance
		};
		laytpl($("#balance").html()).render(data, function(html) {
			layer.open({
				title: '调整储值余额',
				skin: 'layer-tips-class',
				type: 1,
				area: ['800px'],
				content: html,
				end: function () {
					repeat_flag = false;
				}
			});
		});
	}

	function saveGrowth(e) {
		var growth = $(e).attr('data-num');
		var data = {
			growth : growth
		};
		laytpl($("#growth").html()).render(data, function(html) {
			layer.open({
				title: '调整成长值',
				skin: 'layer-tips-class',
				type: 1,
				area: ['800px'],
				content: html,
				end: function () {
					repeat_flag = false;
				}
			});
		});
	}

	function editMemberLevel(){
		laytpl($("#memberLevel").html()).render({}, function(html) {
			layer.open({
				title: '设置会员等级',
				skin: 'select-level-layer',
				type: 1,
				area: ['400px', '300px'],
				content: html,
				success: function(){
					form.render();

					form.on('radio(level_type)', function (data) {
						$('.level-type').hide();
						$('.level-type.type-' + data.value).show();
					})

					form.on('select(member_card)', function (data) {
						$('.member-card').hide();
						$('.member-card-' + data.value).show();
					})
				},
				btn: ['保存', '取消'],
				yes: function () {
					layer.confirm('是否确定变更该客户的会员等级？',{title: '会员等级变更确认'}, function(index){
						let data = {
							level_type: $('[name="level_type"]:checked').val() || 0,
							member_id: '{$member_info.data.member_id}'
						}
						data.level_id = data.level_type == 0 ? $('[name="member_level"]').val() : $('[name="member_card"]').val();
						if (data.level_id == 0) {
							layer.msg((data.level_type == 0 ? '请选择会员等级' : '请选择会员卡'));
							return;
						}
						if (data.level_type == 1) data.period_unit = $('[name="member_card_'+ data.level_id +'"]:checked').val();

						$.ajax({
							type: "POST",
							url: ns.url("shop/member/changememberlevel"),
							data: data,
							dataType: 'JSON',
							success: function(res) {
								if (res.code == 0) {
									location.reload();
								} else {
									layer.msg(res.message);
								}
							}
						});
						layer.closeAll();
					});
				}
			});
		});
	}

	function editNickname(event){
		var nickname = $(event).prev('span').text();
		var html = `<div class="layui-form form-wrap">
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:auto"><span class="required">*</span>昵称：</label>
							<div class="layui-input-block" style="margin-left: 0;">
								<input name="nickname" type="text" lay-verify="required" value="`+ nickname +`" class="layui-input len-mid">
							</div>
						</div>
					</div>`;
		layer.open({
			title: '编辑昵称',
			skin: 'edit-member-layer',
			type: 1,
			area: '360px',
			content: html,
			success: function(){
				form.render();
			},
			btn: ['保存', '取消'],
			yes: function () {
				var data = {nickname: $.trim($('[name="nickname"]').val())};
				if (!reg.required.test(data.nickname)) {
					layer.msg('请输入昵称', {icon: 5});
					return;
				}
				editMember(data, function(res){
					if (res.code == 0) {
						$(event).prev('span').text(data.nickname);
						layer.closeAll();
					} else {
						layer.msg(res.message);
					}
				});
			}
		})
	}

	function editRealname(event){
		var realname = $.trim($(event).prev('span').text()) != '暂无' ? $.trim($(event).prev('span').text()) : '';
		var html = `<div class="layui-form form-wrap">
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:auto"><span class="required">*</span>真实姓名：</label>
							<div class="layui-input-block" style="margin-left: 0;">
								<input name="realname" type="text" lay-verify="required" value="`+ realname +`" class="layui-input len-mid">
							</div>
						</div>
					</div>`;
		layer.open({
			title: '真实姓名',
			skin: 'edit-member-layer',
			type: 1,
			area: '380px',
			content: html,
			success: function(){
				form.render();
			},
			btn: ['保存', '取消'],
			yes: function () {
				var data = {realname: $.trim($('[name="realname"]').val())};
				if (!reg.required.test(data.realname)) {
					layer.msg('请输入真实姓名', {icon: 5});
					return;
				}
				editMember(data, function(res){
					if (res.code == 0) {
						$(event).prev('span').text(data.realname);
						layer.closeAll();
					} else {
						layer.msg(res.message);
					}
				});
			}
		})
	}

	function editMobile(event){
		var realname = $.trim($(event).prev('span').text()) != '暂无' ? $.trim($(event).prev('span').text()) : '';
		var html = `<div class="layui-form form-wrap">
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:auto"><span class="required">*</span>手机号：</label>
							<div class="layui-input-block" style="margin-left: 0;">
								<input name="mobile" type="text" lay-verify="required" value="`+ realname +`" class="layui-input len-mid">
							</div>
						</div>
					</div>`;
		layer.open({
			title: '手机号',
			skin: 'edit-member-layer',
			type: 1,
			area: '380px',
			content: html,
			success: function(){
				form.render();
			},
			btn: ['保存', '取消'],
			yes: function () {
				var data = {mobile: $.trim($('[name="mobile"]').val())};
				if (!reg.required.test(data.mobile)) {
					layer.msg('手机号', {icon: 5});
					return;
				}
				if (!ns.parse_mobile(data.mobile)) {
					layer.msg('请输入正确的手机号', {icon: 5});
					return;
				}
				editMember(data, function(res){
					if (res.code == 0) {
						$(event).prev('span').text(data.mobile);
						layer.closeAll();
					} else {
						layer.msg(res.message);
					}
				});
			}
		})
	}

	function editBirthday(event){
		var birthday = $(event).prev('span').attr('data-value');
		var html = `<div class="layui-form form-wrap">
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:auto"><span class="required">*</span>生日：</label>
							<div class="layui-input-block" style="margin-left: 0;">
								<input name="birthday" type="text" id="birthday" value="" class="layui-input len-mid">
							</div>
						</div>
					</div>`;
		layer.open({
			title: '生日',
			skin: 'edit-member-layer',
			type: 1,
			area: '360px',
			content: html,
			success: function(){
				laydate.render({
					elem: '#birthday',
					max: 0
				});
				form.render();
			},
			btn: ['保存', '取消'],
			yes: function () {
				var data = {birthday: $('[name="birthday"]').val()};
				if (!reg.required.test(data.birthday)) {
					layer.msg('请选择生日', {icon: 5});
					return;
				}
				editMember(data, function(res){
					if (res.code == 0) {
						$(event).prev('span').text(data.birthday);
						// $(event).prev('span').attr('data-value', data.sex);
						layer.closeAll();
					} else {
						layer.msg(res.message);
					}
				});
			}
		})
	}

	function editSex(event){
		var sex = $(event).prev('span').attr('data-value');
		var html = `<div class="layui-form form-wrap">
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:auto"><span class="required">*</span>性别：</label>
							<div class="layui-input-block" style="margin-left: 0;">
								<input type="radio" name="sex" value="1" title="男" `+ (sex == 1 ? 'checked' : '') +`>
								<input type="radio" name="sex" value="2" title="女" `+ (sex == 2 ? 'checked' : '') +`>
							</div>
						</div>
					</div>`;
		layer.open({
			title: '性别',
			skin: 'edit-member-layer',
			type: 1,
			area: '270px',
			content: html,
			success: function(){
				form.render();
			},
			btn: ['保存', '取消'],
			yes: function () {
				var data = {sex: $('[name="sex"]:checked').val()};
				if (!data.sex) {
					layer.msg('请选择性别', {icon: 5});
					return;
				}
				editMember(data, function(res){
					if (res.code == 0) {
						$(event).prev('span').text($('[name="sex"]:checked').attr('title'));
						$(event).prev('span').attr('data-value', data.sex);
						layer.closeAll();
					} else {
						layer.msg(res.message);
					}
				});
			}
		})
	}

	function editMobile(event){
		var mobile = $.trim($(event).prev('span').text()) != '暂无' ? $.trim($(event).prev('span').text()) : '';
		var html = `<div class="layui-form form-wrap">
						<div class="layui-form-item">
							<label class="layui-form-label" style="width:auto"><span class="required">*</span>手机号：</label>
							<div class="layui-input-block" style="margin-left: 0;">
								<input name="mobile" type="number" value="`+ mobile +`" class="layui-input len-mid">
							</div>
						</div>
					</div>`;
		layer.open({
			title: '编辑手机号',
			skin: 'edit-member-layer',
			type: 1,
			area: '370px',
			content: html,
			success: function(){
				form.render();
			},
			btn: ['保存', '取消'],
			yes: function () {
				var data = {mobile: $('[name="mobile"]').val()};
				if (!reg.required.test(data.mobile)) {
					layer.msg('请输入手机号', {icon: 5});
					return;
				}
				if (!reg.mobile.test(data.mobile)) {
					layer.msg('请输入正确的手机号', {icon: 5});
					return;
				}
				editMember(data, function(res){
					if (res.code == 0) {
						$(event).prev('span').text(data.mobile);
						layer.closeAll();
					} else {
						layer.msg(res.message);
					}
				});
			}
		})
	}

	function editMember(data, callback){
		if(repeat_flag) return false;
		repeat_flag = true;

		data.member_id = '{$member_info.data.member_id}';

		$.ajax({
			url: ns.url("shop/member/editMember"),
			data: data,
			dataType: 'JSON', //服务器返回json格式数据
			type: 'POST', //HTTP请求类型
			success: function(res) {
				repeat_flag = false;
				typeof callback == 'function' && callback(res);
			}
		});
	}

	function editMemberAddress(event){
		var html = `<div class="layui-form form-wrap">
			<div class="layui-form-item">
				<label class="layui-form-label" style="width:auto"><span class="required">*</span>所在地区：</label>
				<div class="layui-input-inline len-mid" style="margin: 0;">
					<input name="full_address" type="text" lay-verify="required" value="{$member_info.data.full_address}" class="layui-input len-mid">
				</div>
			</div>
		</div>
		<input name="province_id" type="hidden" value="{$member_info.data.province_id}" class="layui-input len-mid">
		<input name="city_id" type="hidden" value="{$member_info.data.city_id}" class="layui-input len-mid">
		<input name="district_id" type="hidden" value="{$member_info.data.district_id}" class="layui-input len-mid">
		<div class="layui-form form-wrap">
			<div class="layui-form-item">
				<label class="layui-form-label" style="width:auto"><span class="required">*</span>详细地址：</label>
				<div class="layui-input-block" style="margin-left: 0;">
					<input name="address" type="text" lay-verify="required" value="{$member_info.data.address}" class="layui-input len-mid">
				</div>
			</div>
		</div>`;
		layer.open({
			title: '会员地址',
			skin: 'edit-member-layer',
			type: 1,
			area: '380px',
			content: html,
			success: function(){
				form.render();
				if (!areaTree.length) {
					$.ajax({
						url : ns.url("shop/express/getareatree"),
						dataType: 'JSON',
						type: 'POST',
						async: false,
						success: function(res) {
							areaTree = res.data;
						}
					})
				}

				var _cascader = layCascader({
					elem: $('[name="full_address"]'),
					options: areaTree,
					separator: '-',
					props: {
						value: 'id',
						label: 'name',
						children: 'children'
					}
				});
				{if !empty($member_info.data.full_address)}
				_cascader.setValue({$member_info.data.district_id});
				{/if}

					_cascader.changeEvent(function (value, node) {
						$('[name="province_id"]').val(node.path[0] ? node.path[0].data.id : 0)
						$('[name="city_id"]').val(node.path[1] ? node.path[1].data.id : 0)
						$('[name="district_id"]').val(node.path[2] ? node.path[2].data.id : 0)
						var fullAddress = [];
						node.path.forEach(function (item) {
							fullAddress.push(item.data.name);
						})
						$('[name="full_address"]').val(fullAddress.join('-'));
					});
				},
				btn: ['保存', '取消'],
						yes: function () {
					var data = {
						province_id: $.trim($('[name="province_id"]').val()),
						city_id: $.trim($('[name="city_id"]').val()),
						district_id: $.trim($('[name="district_id"]').val()),
						address: $.trim($('[name="address"]').val()),
						full_address: $.trim($('[name="full_address"]').val())
					};
					if (!reg.required.test(data.full_address)) {
						layer.msg('请选择所在地区', {icon: 5});
						return;
					}
					if (!reg.required.test(data.address)) {
						layer.msg('请输入详细地址', {icon: 5});
						return;
					}
					editMember(data, function(res){
						if (res.code == 0) {
							$(event).prev('span').text(data.realname);
							layer.closeAll();
							setTimeout(function(){
								location.reload()
							}, 1500)
						} else {
							layer.msg(res.message);
						}
					});
				}
			})
	}
</script>
<!-- 积分弹框html -->
<script type="text/html" id="point">
	<div class="layui-form integral-bounced">
		<div class="layui-form-item">
			<label class="layui-form-label">当前积分：</label>
			<div class="layui-input-block account-value">{{ parseInt(d.point) }}</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">调整数额：</label>
			<div class="layui-input-block amount">
				<input type="number" value="0" placeholder="请输入调整数额" name="adjust_num" lay-verify="num" class="layui-input len-short">
			</div>
			<span class="word-aux">调整数额与当前积分数相加不能小于0</span>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">备注：</label>
			<div class="layui-input-block len-long">
				<textarea class="layui-textarea" name="remark" placeholder="请输入备注" maxlength="150"></textarea>
			</div>
		</div>

		<div class="form-row" style="margin-left: 200px;">
			<button class="layui-btn" lay-submit lay-filter="savePoint">确定</button>
		</div>

		<input type="hidden" name="member_id" value="{$member_info.data.member_id}" />
		<input type="hidden" name="point" value="{{ d.point }}" />
	</div>
</script>

<!-- 余额弹框html -->
<script type="text/html" id="balance">
	<div class="layui-form">
		<div class="layui-form-item">
			<label class="layui-form-label">当前储值余额：</label>
			<div class="layui-input-block account-value">{{ d.balance }}</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">调整数额：</label>
			<div class="layui-input-block">
				<input type="number" value="0" placeholder="请输入调整数额" name="adjust_num" lay-verify="num" class="layui-input len-short">
			</div>
			<span class="word-aux">调整数额与当前储值余额相加不能小于0</span>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">备注：</label>
			<div class="layui-input-block len-long">
				<textarea class="layui-textarea" name="remark" placeholder="请输入备注" maxlength="150"></textarea>
			</div>
		</div>

		<div class="form-row" style="margin-left: 200px;">
			<button class="layui-btn" lay-submit lay-filter="saveBalance">确定</button>
		</div>

		<input type="hidden" name="member_id" value="{$member_info.data.member_id}" />
		<input type="hidden" name="point" value="{{ d.balance }}" />
	</div>
</script>

<!-- 成长值弹框html -->
<script type="text/html" id="growth">
	<div class="layui-form">
		<div class="layui-form-item">
			<label class="layui-form-label">当前成长值：</label>
			<div class="layui-input-block account-value">{{ d.growth }}</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">调整数额：</label>
			<div class="layui-input-block">
				<input type="number" value="0" placeholder="请输入调整数额" name="adjust_num" lay-verify="num" class="layui-input len-short">
			</div>
			<span class="word-aux">调整数额与当前成长值相加不能小于0</span>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">备注：</label>
			<div class="layui-input-block len-long">
				<textarea class="layui-textarea" name="remark" placeholder="请输入备注" maxlength="150"></textarea>
			</div>
		</div>

		<div class="form-row" style="margin-left: 200px;">
			<button class="layui-btn" lay-submit lay-filter="saveGrowth">确定</button>
		</div>

		<input type="hidden" name="member_id" value="{$member_info.data.member_id}" />
		<input type="hidden" name="point" value="{{ d.growth }}" />
	</div>
</script>

<script type="text/html" id="memberLevel">
	<div class="layui-form" id="setMemberLevel">
		<div class="layui-form-item">
			<label class="layui-form-label sm">类型：</label>
			<div class="layui-input-block">
				<input type="radio" name="level_type" value="0" title="会员等级" checked lay-filter="level_type">
				<input type="radio" name="level_type" value="1" title="会员卡" lay-filter="level_type">
			</div>
		</div>
		<div class="level-type type-0">
			<div class="layui-form-item">
				<label class="layui-form-label sm">会员等级：</label>
				<div class="layui-input-block len-mid">
					<select name="member_level">
						<option value="0">请选择会员等级</option>
						{foreach name="member_level_list" item="vo"}
						{if $vo.level_type eq 0}
						<option value="{$vo.level_id}" {if $vo.level_id eq $member_info.data.member_level}selected{/if}>{$vo.level_name}</option>
						{/if}
						{/foreach}
					</select>
				</div>
			</div>
		</div>
		<div class="level-type type-1" style="display: none">
			<div class="layui-form-item">
				<label class="layui-form-label sm">会员卡：</label>
				<div class="layui-input-block len-mid">
					<select name="member_card" lay-filter="member_card">
						<option value="0">请选择会员卡</option>
						{foreach name="member_level_list" item="vo"}
						{if $vo.level_type eq 1}
						<option value="{$vo.level_id}" {if $vo.level_id eq $member_info.data.member_level}selected{/if}>{$vo.level_name}</option>
						{/if}
						{/foreach}
					</select>
				</div>
			</div>
			{foreach name="member_level_list" item="vo"}
			{if $vo.level_type eq 1}
			<div class="layui-form-item member-card member-card-{$vo.level_id}" style="display: none">
				<label class="layui-form-label sm">发卡规格：</label>
				<div class="layui-input-block">
					{foreach :json_decode($vo.charge_rule, true) as $key => $money}
					<input type="radio" name="member_card_{$vo.level_id}" value="{$key}" title="{$level_time[$key]}/{$money}元" checked>
					{/foreach}
				</div>
			</div>
			{/if}
			{/foreach}
		</div>
	</div>
</script>
{/block}